package com.example.demo.qy.controller;

import com.example.demo.common.utils.PageUtil;
import com.example.demo.common.utils.ResultUtil;
import com.example.demo.common.vo.PageVo;
import com.example.demo.common.vo.Result;
import com.example.demo.qy.model.WeatherFuture;
import com.example.demo.qy.service.WeatherFutureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "WeatherFuture")
@RestController
public class WeatherFutureController {

    @Autowired
    private WeatherFutureService weatherFutureService;

    @RequestMapping(value = "/WeatherFuture/get/{id}",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "通过id获取")
    public Result<WeatherFuture> get(@PathVariable String id){
        WeatherFuture entity = weatherFutureService.get(id);
        return new ResultUtil<WeatherFuture>().setData(entity);
    }

    @RequestMapping(value = "/WeatherFuture/getAll",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取全部数据")
    public Result<List<WeatherFuture>> getAll(){
        List<WeatherFuture> list = weatherFutureService.getAll();
        return new ResultUtil<List<WeatherFuture>>().setData(list);
    }

    @RequestMapping(value = "/WeatherFuture/getByPage",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "分页获取")
    public Result<Page<WeatherFuture>> getByPage(@ModelAttribute PageVo page){
        Page<WeatherFuture> list = weatherFutureService.findAll(PageUtil.initPage(page));
        return new ResultUtil<Page<WeatherFuture>>().setData(list);
    }

    @RequestMapping(value = "/WeatherFuture/save",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "保存数据")
    public Result<WeatherFuture> save(@ModelAttribute WeatherFuture entity){
        WeatherFuture e = weatherFutureService.save(entity);
        return new ResultUtil<WeatherFuture>().setData(e);
    }

    @RequestMapping(value = "/WeatherFuture/update",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "更新数据")
    public Result<WeatherFuture> update(@ModelAttribute WeatherFuture entity){
        WeatherFuture e = weatherFutureService.update(entity);
        return new ResultUtil<WeatherFuture>().setData(e);
    }

    @RequestMapping(value = "/WeatherFuture/del",method = RequestMethod.DELETE)
    @ResponseBody
    @ApiOperation(value = "删除数据")
    public Result<Object> delAll(@ModelAttribute WeatherFuture entity){
        weatherFutureService.delete(entity);
        return new ResultUtil<Object>().setSuccessMsg("删除数据成功");
    }

    @RequestMapping(value = "/WeatherFuture/delByIds",method = RequestMethod.DELETE)
    @ResponseBody
    @ApiOperation(value = "批量通过ids删除")
    public Result<Object> delAllByIds(@RequestParam String[] ids){
        for(String id:ids){
            weatherFutureService.delete(id);
        }
        return new ResultUtil<Object>().setSuccessMsg("批量删除数据成功");
    }

}
